#include <stdio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{

	int fd;
	void* addr;
	int i = 0;

	//打开文件
	fd = open("test", O_RDWR);
	if(fd < 0)
	{
		perror("open");
	}


	//创建共享内存映射
	addr = mmap(NULL, 1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	if(addr == MAP_FAILED)
	{

		perror("mmap");
	}
	
	while(1)
	{

		printf("read: %s",(char*)addr);
		sleep(1);
	}

}
